//
//  ControlFlowViewController.swift
//  test_swift
//
//  Created by fangyuan ding on 2021/5/31.
//

import UIKit

class ControlFlowViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

       
        for i in 0...3 {
            print(i)
        }
        for name in ["Tom","Ben","Mary"] {
            print(name)
        }

        for ch in "Hello, word!" {
            print(ch)
        }

        for (animal,numberOfLegs) in ["Spider": 8, "Ant": 6, "Cat": 4] {
            print("\(animal) has \(numberOfLegs) legs!")
        }

        for dic in ["Spider": 8, "Ant": 6, "Cat": 4] {
            print("\(dic.key) has \(dic.value) legs!")
        }
        
        
        for tickMark in stride(from: 0, to: 10, by: 2) {
            print(tickMark)
        }
        for tickMark in stride(from: 0, through: 10, by: 2) {
            print(tickMark)
        }
        
        let approximateCount = 62
        let countedThings = "moons orbiting Saturn"
        let naturalCount: String
        switch approximateCount {
        case 0:
            naturalCount = "no"
        case 1..<5:
            naturalCount = "a few"
        case 5..<12:
            naturalCount = "several"
        case 12..<100:
            naturalCount = "dozens of"
        case 100..<1000:
            naturalCount = "hundreds of"
        default:
            naturalCount = "many"
        }
        print("There are \(naturalCount) \(countedThings).")
        //There are dozens of moons orbiting Saturn.
        
        let point = (1,1)
        switch point {
        case (0,0):
            print("\(point) is at the origin")
        case (_,0):
            print("\(point) is on the x-axis")
        case (0,_):
            print("\(point) is on the y-axis")
        case (-2...2,-2...2):
            print("\(point) is inside the box")
        default:
            print("\(point) is outside of the box")
        }
        
        let point2 = (2,0)
        switch point2 {
        case (let x,0):
            print("on the x-axis with a x value of \(x)")
        case (0,let y):
            print("on the y-axis with a y value of \(y)")
        case (let x,let y):
            print("somewhere else at (\(x), \(y))")
        }
        //on the x-axis with a x value of 2
        let point3 = (1,-1)
        switch point3 {
        case let (x, y) where x == y:
            print("(\(x), \(y)) is on the line y = x")
        case let (x, y) where x == -y:
            print("(\(x), \(y)) is on the line y = -x")
        case let (x, y) :
            print("(\(x), \(y)) is just some arbitrary point")
        }


    }
    

  

}
